package com.itheima.controller;


import com.itheima.aop.Log;
import com.itheima.entity.Emp;
import com.itheima.entity.EmpQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description EmpController
 * @Author 你的名字拼接或昵称
 * @Date 2025-09-03
 */
@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {

   @Autowired

   private EmpService empService;

  @GetMapping
   public Result page(EmpQueryParam param){
     PageBean pageBean =empService.page(param);
     return Result.success(pageBean);
  }
    @Log
@PostMapping
    public Result save(@RequestBody Emp emp){
    log.info("save",emp);
    empService.save(emp);
      return Result.success();
}

    @Log
@DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){

    empService.delete(ids);
    return Result.success();
}

@GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
      Emp emp=empService.getByBId(id);
      return Result.success(emp);
}
    @Log
@PutMapping
    public Result update(@RequestBody Emp emp){
      empService.update(emp);
      return Result.success();
}
@GetMapping("/list")
    public Result getList(){
      List<Emp> emps=empService.getList();
      return Result.success(emps);
}
}
